package logic

import (
	"context"
	"gorm.io/gorm"
	"store/models/mysql"

	"store/storerpc/internal/svc"
	"store/storerpc/storerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoreUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreUpdateLogic {
	return &StoreUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StoreUpdateLogic) StoreUpdate(in *storerpc.StoreUpdateRequest) (*storerpc.StoreUpdateResponse, error) {
	// todo: add your logic here and delete this line
	store := mysql.Store{
		Model:      gorm.Model{ID: uint(in.Id)},
		StoreName:  in.StoreName,
		Nickname:   in.Nickname,
		Address:    in.Address,
		Price:      in.Price,
		Shopkeeper: in.Shopkeeper,
	}
	mysql.Db.Debug().Model(&store).Updates(&store)
	return &storerpc.StoreUpdateResponse{Id: int64(store.ID)}, nil
}
